﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NbfsiLogin
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string JSessionID = textBox1.Text;
            String verifyCode = textBox2.Text;
            String postDataStr = String.Format("uuid=ac868bbe-a44a-4185-bb54-67d741c2867c&ukey=83a432e3-c19b-41b4-8477-4c56f671c093&md5=bd6a317a2c9568b3496ebca5433c87ad&loginName=Yujp1&password=123456&verifycode={0}", verifyCode);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.nbfsi.gov.cn/spjcgx/login.jsp");
            request.Method = "POST";
            request.Accept = "image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, */*";
            request.Referer = "http://www.nbfsi.gov.cn/spjcgx/login.jsp";
            request.Headers.Add("Accept-Language", "zh-CN;");
            request.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)";
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = postDataStr.Length;
            request.Headers.Add("Accept-Encoding", "gzip, deflate;");
            request.Host = "www.nbfsi.gov.cn";
            //request.Connection = "Keep-Alive";
            request.Headers.Add("Pragma", "no-cache;");
            request.Headers.Add("Cookie", String.Format("save=null; JSESSIONID={0}", JSessionID));

            Stream myRequestStream = request.GetRequestStream();
            StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312"));
            myStreamWriter.Write(postDataStr);
            myStreamWriter.Close();


            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream myResponseStream = response.GetResponseStream();
            StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
            string retString = myStreamReader.ReadToEnd();
            myStreamReader.Close();
            myResponseStream.Close();


            System.Diagnostics.Process.Start(textBox3.Text, "http://www.nbfsi.gov.cn/spjcgx/applications/terminal/Desktop.jsp");
        }

        private void Form2_Load(object sender, EventArgs e)
        {

        }
    }
}
